package com.xdb.sqlparser.dialect.oracle.ast.expr;

import com.xdb.sqlparser.ast.SQLExpr;
import com.xdb.sqlparser.ast.AbstractSQLExprImpl;
import com.xdb.sqlparser.dialect.oracle.visitor.OracleASTVisitor;
import com.xdb.sqlparser.visitor.SQLAstVisitor;

public class OracleExtractExpr extends AbstractSQLExprImpl implements OracleExpr {

	private OracleDateTimeUnit unit;
	private SQLExpr from;

	public OracleExtractExpr() {

	}

	public OracleDateTimeUnit getUnit() {
		return this.unit;
	}

	public void setUnit(OracleDateTimeUnit unit) {
		this.unit = unit;
	}

	public SQLExpr getFrom() {
		return this.from;
	}

	public void setFrom(SQLExpr from) {
		this.from = from;
	}

	protected void accept0(SQLAstVisitor visitor) {
		this.accept0((OracleASTVisitor) visitor);
	}

	public void accept0(OracleASTVisitor visitor) {
		if (visitor.visit(this)) {
			acceptChild(visitor, this.from);
		}

		visitor.endVisit(this);
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((from == null) ? 0 : from.hashCode());
		result = prime * result + ((unit == null) ? 0 : unit.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		OracleExtractExpr other = (OracleExtractExpr) obj;
		if (from == null) {
			if (other.from != null) {
				return false;
			}
		} else if (!from.equals(other.from)) {
			return false;
		}
		if (unit != other.unit) {
			return false;
		}
		return true;
	}

}
